﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Workstation;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers
{
    /// <summary>
    /// 工位管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkStationController : ControllerBase
    {
        private readonly IMediator mediator;

        public WorkStationController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 工位管理信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateWorkStation(CreateWorkstationCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工位管理信息展示接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiPaging<WorkStationDto>> GetWorkStation([FromQuery]GetWorkStationCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工位管理信息更新接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateWorkStation(UpdateWorkstationCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工位管理信息删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteWorkStation(DeletetWorkstationCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 工位管理信息批量删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeWorkStation(DeletetRangeWorkstationCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
